<template>
	<view>
		<view class="edgeInsetTop"></view>
		<view class="address cu-list menu-avatar margin-bj  radius-bock">
			<view class="cu-item">
				<view class="cu-avatar  cu-avatar1 round wanl-bg-orange"><text class="wlIcon-weizhi1"></text>
				</view>
				<view class="content" v-if="addressData.address" @tap="userAddress()">
					<view>
						<text class="wanl-pip margin-right-sm">{{ addressData.name }}</text>
						<text class="wanl-gray-light text-sm">{{ addressData.mobile }}</text>
					</view>
					<view class="text-sm wanl-pip text-cut mt12">{{ addressData.province}}
						{{ addressData.city }}
						{{ addressData.district }} {{ addressData.address }}
					</view>
				</view>
				<view class="content" @tap="addAddress('newadd')" v-else>
					<view class="text-sm wanl-pip text-cut">点击此处填写收货地址</view>
				</view>
				<view class="action"><text class="wlIcon-fanhui2 text-lg"></text></view>
			</view>
		</view>

		<view class="wanl-order">
			<view v-for="(shop, index) in orderData.lists" :key="index" class="lists bg-white margin-bj radius-bock">
				<view class="shopname">
					<text class="wlIcon-dianpu2 text-orange margin-right-sm"></text>
					<text class="wanl-pip text-df">{{ shop.shop_name }} (距您 <text class="error fb">{{shop.dist}}</text>
						km)</text>
				</view>
				<view class="cu-list menu-avatar">
					<view class="" v-for="(goods, key) in shop.products" :key="key">
						<view class="cu-item margin-bottom">
							<view class="cu-avatar radius-bock"
								:style="{ backgroundImage: 'url(' + $wanlshop.oss(goods.image, 77, 77) + ')' }"></view>
							<view class="content">
								<view class="text-sm text-cut-2 overflow_3">{{ goods.title }}</view>
								<view class="wanl_sku text-sm">
									<text v-for="(item, skey) in goods.sku.difference" :key="skey">
										<block v-if="skey != 0">-</block>{{ item }}
									</text>
								</view>
							</view>
							<view class="action">

								<view class="wanl-pip text-sm text-price text-dec">{{ goods.sku.market_price }}</view>
								<view class=" text-sm text-price u-m-t-0 u-m-l-4">{{ goods.sku.price }}</view>

								<view class="wanl-gray-light text-sm">x{{ goods.number }}</view>
							</view>
						</view>
						<!-- 以前的配送方式 （每个商品都有费用）-->
						<view v-if="false">
							<form>
								<view class="cu-form-group" @tap="setFreight(index, 1,'freight')">
									<view class="wanl-gray-light title">配送方式</view>
									<view class="picker">
										<block v-if="goods['s_freight_detail']">
											{{goods['s_freight_detail']['name']}}
										</block>
										<block v-else>
											<text class="text-gray">请选择</text>
										</block>
										<text class="wlIcon-fanhui2 margin-left"></text>
									</view>
								</view>
								<view class="cu-form-group" @tap="setFreightData(index,key)"
									v-if="goods['s_freight_id'] && goods['freight_items_map'][goods['s_freight_id']]['child'] && 4 == 7">
									<view class="wanl-gray-light title">配送车型</view>
									<view class="picker">
										<block
											v-if="goods['s_freight_data_detail'] && goods['s_freight_data_detail']['name']">
											{{goods['s_freight_data_detail']['name']}}
										</block>
										<block v-else>
											<text class="text-gray">请选择</text>
										</block>
										<text class="wlIcon-fanhui2 margin-left"></text>
									</view>
								</view>
								<view class="cu-form-group">
									<view class="wanl-gray-light title">配送费用</view>
									<view class="picker"><text
											class="text-price margin-left-xs">{{goods.freight_new}}</text></view>
								</view>
								<view class="cu-form-group" @tap="setTransportType(index, key)"
									v-if="goods['s_freight_id'] && goods['freight_items_map'][goods['s_freight_id']]['child']">
									<view class="wanl-gray-light title">搬运类型</view>
									<view class="picker">
										<block v-if="goods['s_transport_detail']">
											{{goods['s_transport_detail']['name']}}
										</block>
										<block v-else>
											<text class="text-gray">请选择</text>
										</block>
										<text class="wlIcon-fanhui2 margin-left"></text>
									</view>
								</view>
								<view class="cu-form-group" v-if="goods['s_transport_id']==1">
									<view class="wanl-gray-light title">搬运层数</view>
									<view class="picker">
										<block v-if="goods['s_transport_id']==1">
											<view class="wanl-numberBox solid">
												<view @tap="set_transport_count(index, key, -1)">
													<text class="wlIcon-jian round text-gray"></text>
												</view>
												<view>{{ goods.transport_count }}</view>
												<view @tap="set_transport_count(index, key, 1)">
													<text class="wlIcon-tianjia round"></text>
												</view>
											</view>
										</block>
										<block v-else-if="goods['s_transport_id']==0 || goods['s_transport_id']==-1">
											<text class="text-gray">-</text>
											<text class="wlIcon-fanhui2 margin-left"></text>
										</block>
										<block v-else>
											<text class="text-gray">请选择</text>
											<text class="wlIcon-fanhui2 margin-left"></text>
										</block>

									</view>
								</view>
								<!-- <view class="cu-form-group">
									<view class="wanl-gray-light title">搬运费用</view>
									<view class="picker"><text
											class="text-price margin-left-xs">{{parseFloat(goods.transport_new).toFixed(2)}}</text>
									</view>
								</view> -->
							</form>
						</view>
					</view>
					<view class="">


						<view class="cu-form-group" @tap="setFreight(index, 1,'freight')">
							<view class="wanl-gray-light title">配送方式</view>
							<view class="picker">
								<block v-if="shop['s_freight_detail']">
									{{shop['s_freight_detail']['name']}}
								</block>
								<block v-else>
									<text class="text-gray">请选择</text>
								</block>
								<text class="wlIcon-fanhui2 margin-left"></text>
							</view>

						</view>

						<view v-if="shop['s_freight_detail'] && shop['s_freight_detail']['name'] == '一键到家'"
							class="cu-form-group" @tap="setFreight(index, 1,'service')">
							<view class="wanl-gray-light title">服务</view>
							<view class="picker">
								<block v-if="shop['s_service_detail']">
									{{shop['s_service_detail']['name']}}
								</block>
								<block v-else>
									<text class="text-gray">请选择</text>
								</block>
								<text class="wlIcon-fanhui2 margin-left"></text>
							</view>

						</view>
						<view class="cu-form-group">
							<view class="wanl-gray-light title">配送费用</view>
							<view class="picker"><text class="text-price margin-left-xs">{{shop.freight.price}}</text>
							</view>
						</view>
						<view v-if="shop['s_service_detail'] && shop['s_service_detail']['name'] == '秒送'"
							class="cu-form-group">
							<view class="wanl-gray-light title">秒送费用</view>
							<view class="picker"><text class="text-price margin-left-xs">{{shop.flash_send_fee}}</text>
							</view>
						</view>
						<view class="cu-form-group">
							<view class="wanl-gray-light title">配送时效</view>
							<view class="picker" v-if="shop['s_freight_detail']['name'] == '物流自提'">{{shop.send_time}}
							</view>
							<view class="picker" v-if="shop['s_freight_detail']['name'] == '到店自取'">{{shop.send_time}}
							</view>
							<view class="picker"
								v-if="shop['s_freight_detail']['name'] == '一键到家' && shop['s_service_detail']['name'] !== '秒送'">
								{{shop.home_send_time}}
							</view>
							<view class="picker"
								v-if="shop['s_freight_detail']['name'] == '一键到家' && shop['s_service_detail']['name'] == '秒送'">
								{{shop.flash_send_time}}
							</view>
						</view>

					</view>
				</view>
				<form>
					<!-- <view class="cu-form-group" v-if="cartType">
						<view class="wanl-gray-light title">购买数量</view>
						<uni-number-box :min="1" :max="orderData.lists[0].products[0].sku.stock" :value="shop.number" @change="changeNum"></uni-number-box>
					</view> -->
					<!-- <view class="cu-form-group">
						<view class="wanl-gray-light title">快递运费</view>
						<view class="picker">{{shop.freight.name}} <text class="text-price margin-left-xs">{{shop.freight.price}}</text></view>
					</view> -->
					<view class="cu-form-group" @tap="queryCoupon(index)" style="border-top: 1px solid #eeeeee;">
						<view class="wanl-gray-light title">优惠折扣</view>
						<view class="picker">
							<block v-if="couponData[index]">
								<text class="wlIcon-youhuiquantuangou text-red margin-right-xs"></text>
								<block
									v-if="couponData[index].type == 'reduction' || (couponData[index].type == 'vip' && couponData[index].usertype == 'reduction')">
									<text>满{{Number(couponData[index].limit)}}减</text>
									￥{{Number(couponData[index].price)}}
								</block>
								<block
									v-if="couponData[index].type == 'discount' || (couponData[index].type == 'vip' && couponData[index].usertype == 'discount')">
									<text>满{{Number(couponData[index].limit)}}打</text>
									{{Number(couponData[index].discount)}} 折
								</block>
								<block v-if="couponData[index].type == 'shipping'">
									<text>满{{Number(couponData[index].limit)}}</text>包邮
								</block>
							</block>
							<block v-else>
								<text class="text-gray">请选择</text>
							</block>
							<text class="wlIcon-fanhui2 margin-left"></text>
						</view>
					</view>
					<view class="cu-form-group align-start">
						<view class="wanl-gray-light title">备注</view>
						<textarea maxlength="-1" v-model="shop.remarks" placeholder="订单备注可选"></textarea>
					</view>
				</form>
				<view class="text-right margin-bj text-sm">
					<text class="wanl-gray">共{{ shop.number }}件，</text>
					<view class="u-flex u-row-right" style="align-items: baseline;">
						<view class="u-flex" style="align-items: baseline;">
							<view>已优惠：</view>
							<text class="text-price text-sm wanl-gray text-dec">{{ shop.coupon_goods || 0}}


							</text>

							<view class="u-m-l-14">小计：</view>
							<text class="text-price text-orange m-price">{{ shop.sub_price }}</text>

						</view>
					</view>
				</view>
			</view>
			<view class="safeAreaBottom"> </view>
			<!-- 弹出层 -->
			<view class="WANL-MODAL text-sm" @touchmove.stop.prevent="moveHandle">
				<!-- 优惠券 -->
				<view class="cu-modal bottom-modal" :class="modalName == 'coupon' ? 'show' : ''" @tap="hideModal">
					<view class="cu-dialog bg-bgcolor" @tap.stop="">
						<view class="wanl-modal">
							<view class="head padding-bj">
								<view class="content">
									<view class="text-lg">优惠券</view>
								</view>
								<view class="close wlIcon-31guanbi" @tap="hideModal"></view>
							</view>
							<view class="info tac f24">
								注：使用优惠券后，无法使用用户代付功能
							</view>
							<scroll-view class="wanl-coupon scroll-y mt24" scroll-y="true" v-if="couponIndex != null">
								<view v-for="(coupon, index) in orderData.lists[couponIndex].coupon" :key="index"
									:class="coupon.type" class="item margin-bottom-bj radius-bock"
									v-if="shouldShowCoupon(coupon, index)">
									<image :src="$wanlshop.appstc('/coupon/bg_coupon_3x.png')" class="coupon-bg">
									</image>
									<image :src="$wanlshop.appstc('/coupon/img_couponcentre_received_3x.png')"
										class="coupon-sign" v-if="coupon.state"></image>
									<view class="item-left">
										<block
											v-if="coupon.type == 'reduction' || (coupon.type == 'vip' && coupon.usertype == 'reduction')">
											<view class="colour">
												<text class="text-price"></text>
												<text class="prices">{{Number(coupon.price)}}</text>
											</view>
											<view class="cu-tag wanl-gray-dark radius text-sm bg-white">
												满{{Number(coupon.limit)}}减{{Number(coupon.price)}}
											</view>
										</block>
										<block
											v-if="coupon.type == 'discount' || (coupon.type == 'vip' && coupon.usertype == 'discount')">
											<view class="colour">
												<text class="prices">{{Number(coupon.discount)}}</text>
												<text class="discount">折</text>
											</view>
											<view class="cu-tag wanl-gray-dark radius text-sm bg-white">
												满{{Number(coupon.limit)}}打{{Number(coupon.discount)}}折
											</view>
										</block>
										<block v-if="coupon.type == 'shipping'">
											<view class="colour">
												<text class="prices">包邮</text>
											</view>
											<view class="cu-tag wanl-gray-dark radius text-sm bg-white">
												满{{Number(coupon.limit)}}元包邮
											</view>
										</block>
									</view>
									<view class="item-right padding-bj">
										<view class="title">
											<view class="cu-tag sm radius margin-right-xs tagstyle">
												{{coupon.type_text}}
											</view>
											<text class="text-cut wanl-gray text-min">{{coupon.name}}</text>
										</view>
										<view class="content text-min">
											<view class="wanl-gray">

												<view v-if="coupon.grant != '-1' && coupon.shop_id != 0">
													<text class="wlIcon-dot"></text>目前仅剩余 {{coupon.surplus}} 张
												</view>

												<view v-if="coupon.drawlimit != 0 && coupon.shop_id != 0">
													<text class="wlIcon-dot"></text>每人仅限领取 {{coupon.drawlimit}} 张
												</view>

												<block v-if="coupon.pretype == 'fixed'">
													<view>
														<text class="wlIcon-dot"></text>生效 {{coupon.startdate}}
													</view>
													<view>
														<text class="wlIcon-dot"></text>结束 {{coupon.enddate}}
													</view>
												</block>
												<block v-if="coupon.pretype == 'appoint'">
													<view v-if="coupon.validity == 0">
														<text class="wlIcon-dot"></text>未使用前 永久 有效
													</view>
													<view v-else>
														<text class="wlIcon-dot"></text>领取后 {{coupon.validity}} 天有效
													</view>
												</block>
											</view>
											<view class="cu-btn sm round line-colour" v-if="coupon.state">
												<text @tap="onCoupons(index)" v-if="coupon.choice"> 已选择 </text>
												<text @tap="onCoupons(index)" v-if="!coupon.choice">
													立即使用 </text>

											</view>
											<view class="cu-btn sm round" @tap="onReceive(index)" v-if="!coupon.state">
												立即领取
											</view>
										</view>
									</view>
								</view>
							</scroll-view>
							<view class="foot padding-lr-bj"><button
									class="cu-btn bg-gradual-orange round text-bold complete"
									@tap="hideModal">完成</button></view>
						</view>
					</view>
				</view>
				<view class="cu-modal bottom-modal" :class="modalName == 'freight' ? 'show' : ''" @tap="hideModal">
					<view class="cu-dialog bg-bgcolor" @tap.stop="">
						<view class="wanl-modal">
							<view class="head padding-bj">
								<view class="content">
									<view class="text-lg">配送方式</view>
								</view>
								<view class="close wlIcon-31guanbi" @tap="hideModal"></view>
							</view>
							<view class="u-flex u-flex-wrap padding-lr-bj">
								<view class="freight-item mr12" v-for="(freight, index) in freightItems" :key="index"
									:class="{'active': freight['id'] == temp_id }"
									@click="selectFreight(freight['id'], freight,index)">
									{{freight['name']}}
								</view>
								<!-- <view class="freight-item" v-for="(freight, index) in (3 - freightItems.length%3 )"
									:key="index" style="opacity: 0;">
									{{freight}}
								</view> -->
							</view>
							<view class="foot padding-lr-bj"><button
									class="cu-btn bg-gradual-orange round text-bold complete"
									@tap="hideModal">完成</button></view>
						</view>
					</view>
				</view>
				<view class="cu-modal bottom-modal" :class="modalName == 'service' ? 'show' : ''" @tap="hideModal">
					<view class="cu-dialog bg-bgcolor" @tap.stop="">
						<view class="wanl-modal">
							<view class="head padding-bj">
								<view class="content">
									<view class="text-lg">服务</view>
								</view>
								<view class="close wlIcon-31guanbi" @tap="hideModal"></view>
							</view>
							<view class="u-flex u-flex-wrap padding-lr-bj">
								<view class="freight-item mr12" v-for="(freight, index) in freightItems" :key="index"
									:class="{'active': freight['id'] == temp_id1}"
									@click="selectFreight(freight['id'], freight,index)">
									{{freight['name']}}
								</view>
								<!-- <view class="freight-item" v-for="(freight, index) in (3 - freightItems.length%3 )"
									:key="index" style="opacity: 0;">
									{{freight}}
								</view> -->
							</view>
							<view class="foot padding-lr-bj"><button
									class="cu-btn bg-gradual-orange round text-bold complete"
									@tap="hideModal">完成</button></view>
						</view>
					</view>
				</view>
				<view class="cu-modal bottom-modal" :class="modalName == 'freight_data' ? 'show' : ''" @tap="hideModal">
					<view class="cu-dialog bg-bgcolor" @tap.stop="">
						<view class="wanl-modal">
							<view class="head padding-bj">
								<view class="content">
									<view class="text-lg">配送车型</view>
								</view>
								<view class="close wlIcon-31guanbi" @tap="hideModal"></view>
							</view>
							<view class="u-flex u-flex-wrap padding-lr-bj">
								<view class="freight-item mr12" v-for="(freight, index) in frieghtDataItems"
									:key="index" :class="{'active': freight['id'] == temp_id}"
									@click="selectFreightData(freight['id'], freight)">
									{{freight['name']}}
								</view>
								<view class="freight-item" @tap="callPhone()">
									联系客服
								</view>
								<!-- 	<view class="freight-item"
									v-for="(freight, index) in (3 -( frieghtDataItems.length + 1) %3 )" :key="index"
									style="opacity: 0;">
									{{freight}}
								</view> -->
							</view>
							<view class="foot padding-lr-bj"><button
									class="cu-btn bg-gradual-orange round text-bold complete"
									@tap="hideModal">完成</button></view>
						</view>
					</view>
				</view>
				<view class="cu-modal bottom-modal" :class="modalName == 'transport' ? 'show' : ''" @tap="hideModal">
					<view class="cu-dialog bg-bgcolor" @tap.stop="">
						<view class="wanl-modal">
							<view class="head padding-bj">
								<view class="content">
									<view class="text-lg">搬运类型</view>
								</view>
								<view class="close wlIcon-31guanbi" @tap="hideModal"></view>
							</view>
							<view class="u-flex u-flex-wrap padding-lr-bj">
								<view class="freight-item mr12" v-for="(item, index) in transportType" :key="index"
									:class="{'active': item['id'] == temp_transport_id}"
									@click="selectTransportType(item['id'], item)">
									{{item['name']}}
								</view>
								<!-- <view class="freight-item" v-for="(item, index) in (3 - transportType.length%3 )"
									:key="index" style="opacity: 0;">
								</view> -->
							</view>
							<view class="foot padding-lr-bj"><button
									class="cu-btn bg-gradual-orange round text-bold complete"
									@tap="hideModal">完成</button></view>
						</view>
					</view>
				</view>
				<view class="cu-modal bottom-modal show m-safe-area" @tap="show_detail()" v-show="showDetail">
					<view class="cu-dialog bg-bgcolor" @tap.stop="">
						<view class="wanl-modal u-p-b-0">
							<view class="head padding-bj">
								<view class="content">
									<view class="text-lg">优惠说明</view>
								</view>
								<view class="close wlIcon-31guanbi" @tap="show_detail()"></view>
							</view>
							<view class="u-flex-col u-flex-wrap padding-lr-bj u-row-between">
								<view class="coupon-item">
									<view class="title">市场价格</view>
									<view class="wanl-pip text-sm text-price text-dec value text-price">
										{{orderData.statis.order_price?$wanlshop.bcadd(orderData.statis.order_price , orderData.statis.coupon_goods):''}}
									</view>
								</view>
								<view class="coupon-item">
									<view class="title">好饰价格</view>
									<view class="value text-price">{{orderData.statis.order_price}}</view>
								</view>
								<view class="coupon-item">
									<view class="title">配送费用</view>
									<view class="value text-price">{{orderData.statis.freight_new}}</view>
								</view>
								<!-- 	<view class="coupon-item">
									<view class="title">搬运费用</view>
									<view class="value text-price">{{orderData.statis.transport_new}}</view>
								</view> -->
								<view class="coupon-item">
									<view class="title">平台优惠</view>

									<view class="u-flex text-orange">
										<view>
											-
										</view>
										<view class="text-orange value text-price">{{orderData.statis.coupon_goods}}
										</view>
									</view>
								</view>

								<view class="coupon-item">
									<view class="title">代金券</view>
									<view class="u-flex text-orange">
										<view>
											-
										</view>
										<view class="text-orange value text-price">{{orderData.statis.coupon_discount}}
										</view>
									</view>
								</view>

								<view class="coupon-item">
									<view class="title">配送优惠</view>

									<view class="u-flex text-orange">
										<view>
											-
										</view>
										<view class="text-orange value text-price">{{orderData.statis.coupon_freight}}
										</view>
									</view>
								</view>
								<view class="u-flex u-row-right">
									<view class="title">已优惠:</view>
									<view class="text-orange value text-price u-m-l-4">
										{{orderData.statis.allcoupon || 0}}
									</view>
								</view>
							</view>
						</view>


					</view>

				</view>
			</view>
			<view class="wanlian cu-bar tabbar solid-top foot text-df" v-if="orderData.lists.length > 0">
				<view class="u-flex">
					<text class="wanl-gray">共{{ orderData.statis.allnum }}件，</text>

					实付：
					<text
						class="text-price text-orange m-price">{{ $wanlshop.bcadd(orderData.statis.allsub,0)  }}</text>
				</view>
				<!-- <view class="detail u-m-l-56" @click="show_detail">明细</view>
				<u-icon name="arrow-up" v-if="!showDetail" class="u-m-l-4"></u-icon>
				<u-icon name="arrow-down" v-else class="u-m-l-4"></u-icon> -->
				<button v-if="loading" class="cu-btn round lg bg-gradual-orange margin-lr-bj">
					<text class="wlIcon-jiazai wlIconfont-spin margin-right-xs"></text> 提交中...
				</button>
				<button v-else @tap="addOrder" open-type="liveActivity"
					class="cu-btn round lg bg-gradual-orange margin-lr-bj"> 提交订单 </button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: false,
				token: '',
				optionData: {},
				addressData: {},
				modalName: null, // 弹出层
				cartType: null,
				couponData: {},
				couponIndex: null,
				ts: 0,
				orderData: {
					lists: [],
					statis: {
						allnum: 1,
						allsub: 0
					}
				},
				freightItems: [],
				freightIndex: 0,
				freightKey: 0,
				frieghtDataItems: [],
				temp_id: 0,
				temp_id1: 0,
				temp_transport_id: 0,
				transportType: [{
						id: -1,
						name: "无"
					},
					{
						id: 0,
						name: "电梯"
					},
					{
						id: 1,
						name: "步梯"
					}
				],
				transportTypeIndex: 0,
				transportTypeKey: 0,
				showDetail: false,
				onloadNum: 0,
				coupon_ids: [],
			};
		},
		onLoad(option) {
			console.log(JSON.parse(option.data));
			this.optionData = option.data ? JSON.parse(option.data) : [];
			console.log(this.optionData);

			this.cartType = option.type;
			this.loadData(null, 'onload');
		},
		onShow() {


			//this.loadData();
			this.loading = false;

		},

		watch: {


			ts: function() {
				let all_price = 0;
				return
				for (var i = 0; i < this.orderData.lists.length; i++) {
					let item = this.orderData.lists[i]
					console.log(item.transport_new)
					// this.orderData.lists.map(item=>{
					let goods_price = 0;
					let freight_new = 0;
					let transport_new = 0;
					let freightMap = [];
					item.products.map(product => {
						// goods_price = this.$wanlshop.bcadd(goods_price, product.goods_price)
						if (freightMap[product.s_freight_data_id] == undefined) {
							// freight_new = this.$wanlshop.bcadd(freight_new, product.freight_new)
							freightMap[product.s_freight_data_id] = 1
						}

						// transport_new = this.$wanlshop.bcadd(transport_new, product.transport_new)
					})

					item.freight_new = freight_new;
					item.freight_price_bak = freight_new;
					item.transport_new = transport_new;
					console.log(item.transport_new)
					item.goods_price = goods_price;
					// let total_price = this.$wanlshop.bcadd(goods_price, freight_new)
					// total_price = this.$wanlshop.bcadd(total_price, transport_new)

					item.sub_price = total_price;
					// item.coupon_goods = this.$wanlshop.bcsub(item.goods_market_price, item.goods_price);
					// all_price = this.$wanlshop.bcadd(all_price, total_price)
					// this.onCouponsAuto(i)
					// })
				}
				this.orderData.statis.allsub = this.$wanlshop.bcadd(all_price);
				for (var i = 0; i < this.orderData.lists.length; i++) {
					console.log('ts')
					this.onCouponsAuto(i)
				}
			},
			total: function() {
				let data = this.orderData.lists.map(item => {
					return item['sub_price'];
				});
				console.log(data);
				return data;
			}
		},
		methods: {
			shouldShowCoupon(coupon, index) {
				// 获取当前选中的优惠券索引
				const selectedCouponIndex = this.getSelectedCouponIndex();

				// 如果没有选中的优惠券，显示所有非coupon_ids的优惠券
				if (selectedCouponIndex === -1) {
					return !this.coupon_ids.includes(coupon.coupon_id);
				}

				// 如果当前优惠券是选中的优惠券，始终显示
				if (index === selectedCouponIndex) {
					return true;
				}

				// 如果当前优惠券ID在coupon_ids中且不是选中的优惠券，不显示
				if (this.coupon_ids.includes(coupon.coupon_id)) {
					return false;
				}

				// 其他情况显示
				return true;
			},

			getSelectedCouponIndex() {
				// 查找第一个choice为true的优惠券索引
				const coupons = this.orderData.lists[this.couponIndex].coupon;
				for (let i = 0; i < coupons.length; i++) {
					if (coupons[i].choice === true) {
						return i;
					}
				}
				return -1; // 没有选中的优惠券
			},
			async loadData(address_id, type) {
				console.log(address_id);
				this.$api.post({
					url: '/wanlshop/order/getOrderGoodsList',
					loadingTip: '加载中',
					data: {
						data: this.optionData,
						address_id: address_id,
						address: this.$wanlshop.address
					},
					success: res => {
						if (res.info) {
							this.userAddress();
						} else {
							this.token = res.token;
							this.orderData = res.orderData;

							for (let i in res.orderData.lists) {
								console.log(i);
								this.queryCoupon(i, 'onload')
							}
							this.couponData = {}
							if (type) {

								let data = {
									id: 5,
									name: '到店自取'
								}
								setTimeout(() => {
									console.log(res.orderData.lists);
									for (let i in res.orderData.lists) {
										console.log(i);
										this.setFreight(i, data, 'onload')
										this.selectFreight(5, data)
									}
								}, 800)
								this.onloadNum++
							}


							if (res.addressData) {
								this.addressData = res.addressData;
								this.ts = (new Date()).getTime();
							} else {
								this.addAddress('newadd');
							}
						}
					}
				});
			},
			// 提交订单
			async addOrder() {
				const shouldProceed = await this.$wanlshop.setrequestSubscribeMessage([
					'2wtJZbU46iRzk6GMPV5I4lk9B0Sh_bbQk0Zp0tMmyTs',
					'KPkBIdZ6YU68e0cigd-xCVgEXekMGHAuRHeLjokby5Q',
					'J3VyZtBYkExI4G47u1aK83w4-xPM7pW6_GlwLo5I108',
				])
				if (shouldProceed) {
					if (this.orderData.statis.allnum === 0) {
						this.$wanlshop.msg('订单异常')
						return;
					}
					let address_id = this.addressData.id;
					if (address_id === 0) {
						this.$wanlshop.msg('请填写地址')
						return;
					}
					let data = {
							lists: [],
							address_id: address_id
						},
						cart = [];

					let canSubmit = true;
					console.log(this.orderData.lists);
					for (var i = 0; i < this.orderData.lists.length;) {
						let item = this.orderData.lists[i];
						let index = i;
						i++;
						// this.orderData.lists.forEach((item, index)=> {
						data.lists.push({
							shop_id: item.shop_id,
							freight_price: item.freight.price,
							remarks: item.remarks,
							products: [],
							send_type: item['s_freight_id'],
							is_send: item['s_service_id'] == 4 ? 1 : 0,
							//店铺优惠券和其他 在下追加
							coupon_id: this.couponData[index] ? this.couponData[index].id : 0
						});
						let len = item.products.length;
						for (var i1 = 0; i1 < item.products.length;) {
							let goods = item.products[i1]
							i1++;
							// item.products.forEach(goods => {
							// 购物车数据
							cart.push({
								goods_id: goods.id,
								sku_id: goods.sku.id
							});
							// 商品数据
							console.log(goods)

							if (!goods.s_freight_data_id && goods['s_freight_id'] && goods['freight_items_map'][goods[
									's_freight_id']]['child']) {
								uni.showToast({
									title: '请选择配送车型',
									icon: 'none'
								});
								canSubmit = false;
								break;
							}
							if (goods['s_freight_id'] && !goods['freight_items_map'][goods['s_freight_id']]['child']) {
								goods.s_transport_id = -1;
							}

							data.lists[index].products.push({
								goods_id: goods.id,
								number: goods.number,
								sku_id: goods.sku.id,
								freight_id: item.freight.id,
								freight_data_id: goods.s_freight_data_id,
								transport_id: -1,
								transport_count: goods.transport_count,


							});
							if (!canSubmit) break;
							// });
						}
						// });
					}
					if (!canSubmit) return;
					this.loading = true;
					// 提交订单数据data
					this.$api.post({
						url: '/wanlshop/order/addOrder',
						data: {
							order: data,
							token: this.token
						},
						loadingTip: '提交订单中...',
						success: res => {

							this.$store.commit('statistics/order', {
								pay: this.$store.state.statistics.order.pay + res.list.length,
								whole: this.$store.state.statistics.order.whole + res.list.length
							});
							// 如果使用优惠券全局减去
							let coupon = Object.keys(this.couponData).length;
							if (coupon != 0) {
								this.$store.commit('statistics/dynamic', {
									coupon: this.$store.state.statistics.dynamic.coupon - coupon
								});
							}
							// 大厂软件，就是这么迷幻
							if (this.cartType == 'cart') {
								this.$store.dispatch('cart/del');
							}
							this.$wanlshop.to(
								`/pages/user/money/pay?token=${res.token}&data=${JSON.stringify(res.list)}`
							);
						},
						fail: error => {
							this.loading = false;
						}
					});

				}
			},
			// 拉起本地地图
			goNavigation(item) {
				console.log(item);
				if (!item.store_location) return
				let location = item.store_location.split(',')
				this.latitude = location[1]
				this.longitude = location[0]
				// #ifdef MP-WEIXIN

				uni.openLocation({
					latitude: parseFloat(location[1]),
					longitude: parseFloat(location[0]),
					name: item.shopname,
					address: item.store_address,
					success: function(res) {
						console.log('打开系统位置地图成功')
					},
					fail: function(error) {
						console.log(error)
					}
				})

				// #endif
				// #ifdef APP-PLUS
				// 判断系统安装的地图应用有哪些, 并生成菜单按钮
				let _mapName = [{
						title: '高德地图',
						name: 'amap',
						androidName: 'com.autonavi.minimap',
						iosName: 'iosamap://'
					},
					{
						title: '百度地图',
						name: 'baidumap',
						androidName: 'com.baidu.BaiduMap',
						iosName: 'baidumap://'
					},
					{
						title: '腾讯地图',
						name: 'qqmap',
						androidName: 'com.tencent.map',
						iosName: 'qqmap://'
					},
				]
				// 根据真机有的地图软件 生成的 操作菜单
				let buttons = []
				let platform = uni.getSystemInfoSync().platform
				platform === 'android' && _mapName.forEach(item => {
					if (plus.runtime.isApplicationExist({
							pname: item.androidName
						})) {
						buttons.push(item)
					}
				})
				platform === 'ios' && _mapName.forEach(item => {
					console.log(item.iosName)
					if (plus.runtime.isApplicationExist({
							action: item.iosName
						})) {
						buttons.push(item)
					}
				})
				if (buttons.length) {
					plus.nativeUI.actionSheet({ //选择菜单
						title: "选择地图应用",
						cancel: "取消",
						buttons: buttons
					}, function(e) {
						let _map = buttons[e.index - 1]
						_this.openURL(_map, platform)
					})
				} else {
					uni.showToast({
						title: '请安装地图软件',
						icon: 'none'
					})
					return
				}
				// #endif

				// #ifdef H5
				let that = this
				uni.showActionSheet({
					itemList: ['高德地图', '百度地图', '腾讯地图'],
					success: function(res) {
						that.guide(res.tapIndex)
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
				// #endif

			},

			//添加或修改成功之后回调
			async refreshList(data, type) {
				this.$api.post({
					url: '/wanlshop/address/address',
					data: {
						data: data,
						type: 'add'
					},
					success: res => {
						this.addressData = res;
					}
				});
			},
			// 查询优惠券，减缓服务器压力，单独查询（仅查询首次）
			async queryCoupon(index, type) {
				console.log(index);
				// this.ts = (new Date()).getTime();
				let data = this.orderData.lists[index];
				console.log(data)
				if (data.coupon.length == 0) {
					let goods_id = [];
					let shop_category_id = [];
					for (var i = 0; i < data.products.length; i++) {
						goods_id.push(data.products[i]['id']);
						shop_category_id.push(data.products[i]['shop_category_id']);
					};
					this.$api.post({
						url: '/wanlshop/coupon/query',
						data: {
							shop_id: data.shop_id,
							goods_id: this.unique(goods_id),
							shop_category_id: this.unique(shop_category_id),
							price: data.order_price
						},
						success: res => {
							data.coupon = res;
						}
					});
				}
				this.couponIndex = index;
				if (type) return
				this.modalName = 'coupon';
			},
			// 领取优惠券
			async onReceive(index) {
				let coupon = this.orderData.lists[this.couponIndex].coupon[index];
				this.$api.post({
					url: '/wanlshop/coupon/receive',
					loadingTip: '领取中',
					data: {
						id: coupon.id
					},
					success: res => {
						coupon.id = res.id;
						coupon.state = true;
						this.$wanlshop.msg(res.msg);
						this.$store.commit('statistics/dynamic', {
							coupon: this.$store.state.statistics.dynamic.coupon + 1
						});
					}
				});
			},
			// 选中优惠券, 将优惠券放进数组中
			onCoupons(index) {
				var a = this.orderData.lists[this.freightIndex]['s_freight_detail'];
				var b = this.orderData.lists[this.freightIndex]['s_service_detail'];
				let order = this.orderData.lists[this.couponIndex];
				let data = this.orderData.lists[this.couponIndex].coupon;

				// 保存当前优惠券ID
				const currentCouponId = data[index].coupon_id;

				// 切换当前优惠券的选中状态
				data[index].choice = !data[index].choice;

				let coupon_discount = 0;
				let coupon_freight = 0;
				let fee_price = 0;

				// 计算运费基准价格
				if (a.name == '物流自提') {
					fee_price = order.logistics_price.price;
				}
				if (a.name == '快递配送') {
					fee_price = order.freight.price;
				}
				if (a.name == '到店自取') {
					fee_price = order.pickup_price.price;
				}
				if (a.name == '一键到家' && b.name == '无') {
					fee_price = JSON.parse(JSON.stringify(order.freight_send_fee.price));
				}
				if (b.name == '秒送') {
					fee_price = this.$wanlshop.bcadd(order.freight_send_fee.price, order.flash_send_fee);
				}

				if (data[index].choice) {
					// 遍历取消掉其他选择的状态
					for (var i = 0; i < data.length; i++) {
						if (i != index) {
							data[i].choice = false;
						}
					}

					// 将当前优惠券ID添加到coupon_ids数组中
					// 先清空数组，确保单选逻辑
					this.coupon_ids = [];
					this.coupon_ids.push(currentCouponId);

					this.couponData[this.couponIndex] = data[index];

					// 满减券计算
					if (data[index].type == 'reduction' || (data[index].type == 'vip' && data[index].usertype ==
							'reduction')) {
						if (a.name == '物流自提') {
							order.freight.price = order.logistics_price.price;
						}
						if (a.name == '快递配送') {
							order.freight.price = order.freight.price;
						}
						if (a.name == '到店自取') {
							order.freight.price = order.pickup_price.price;
						}
						if (a.name == '一键到家') {
							order.freight.price = order.freight_send_fee.price;
						}

						order.sub_price = this.$wanlshop.bcsub(
							this.$wanlshop.bcadd(order.order_price, fee_price),
							data[index].price
						);
						coupon_discount = data[index].price;
					}

					// 折扣券计算
					if (data[index].type == 'discount' || (data[index].type == 'vip' && data[index].usertype ==
							'discount')) {
						if (a.name == '物流自提') {
							order.freight.price = order.logistics_price.price;
						}
						if (a.name == '快递配送') {
							order.freight.price = order.freight.price;
						}
						if (a.name == '到店自取') {
							order.freight.price = order.pickup_price.price;
						}
						if (a.name == '一键到家') {
							order.freight.price = order.freight_send_fee.price;
						}

						let discount = data[index].discount > 10 ?
							this.$wanlshop.bcdiv(data[index].discount, 100) :
							this.$wanlshop.bcdiv(data[index].discount, 10);

						order.sub_price = this.$wanlshop.bcadd(
							this.$wanlshop.bcmul(order.order_price, discount),
							fee_price
						);
					}

					// 包邮券计算
					if (data[index].type == 'shipping') {
						coupon_freight = fee_price;

						if (a.name === '物流自提' || a.name === '快递配送' || a.name === '一键到家' || a.name == '到店自取') {
							order.freight.price = this.$wanlshop.bcadd(0, 0);
							order.sub_price = order.order_price;
						}

						if (b.name == '秒送') {
							order.sub_price = this.$wanlshop.bcadd(order.order_price, order.flash_send_fee);
						}
					}
				} else {
					// 取消选择，从coupon_ids中移除当前优惠券ID
					const index = this.coupon_ids.indexOf(currentCouponId);
					if (index > -1) {
						this.coupon_ids.splice(index, 1);
					}

					// 恢复原价
					this.couponData[this.couponIndex] = null;

					if (a.name == '物流自提') {
						order.freight = JSON.parse(JSON.stringify(order.myfreight));
						order.sub_price = this.$wanlshop.bcadd(order.logistics_price.price, order.goods_price);
					}
					if (a.name == '快递配送') {
						order.freight = JSON.parse(JSON.stringify(order.myfreight));
						order.sub_price = this.$wanlshop.bcadd(order.freight.price, order.goods_price);
					}

					if (a.name == '到店自取') {
						order.freight = JSON.parse(JSON.stringify(order.myfreight));
						order.sub_price = this.$wanlshop.bcadd(order.pickup_price.price, order.goods_price);
					}

					if (b.name == '无' && a.name == '一键到家') {
						order.freight = JSON.parse(JSON.stringify(order.myfreightsendfee));
						order.sub_price = this.$wanlshop.bcadd(order.freight_send_fee.price, order.goods_price);
					} else if (b.name == '秒送') {
						order.freight = JSON.parse(JSON.stringify(order.myfreightsendfee));
						order.sub_price = this.$wanlshop.bcadd(
							this.$wanlshop.bcadd(order.goods_price, order.freight_send_fee.price),
							order.flash_send_fee
						);
					}
				}

				// 更新运费和优惠信息
				order.freight_new = order.freight.price;
				order.coupon_freight = coupon_freight;
				order.coupon_discount = coupon_discount;

				// 重新计算总计
				this.orderData.statis.allsub = 0;
				this.orderData.statis.coupon_freight = 0;
				this.orderData.statis.coupon_discount = 0;
				this.orderData.statis.coupon_goods = 0;
				this.orderData.statis.allcoupon = 0;
				this.orderData.statis.order_price = 0;
				this.orderData.statis.freight_new = 0;
				this.orderData.statis.transport_new = 0;

				for (var i = 0; i < this.orderData.lists.length; i++) {
					this.orderData.statis.allsub = this.$wanlshop.bcadd(
						this.orderData.statis.allsub,
						this.orderData.lists[i].sub_price
					);
				}

				this.modalName = null;
			},
			onCouponsAuto(orderIndex) {
				let order = this.orderData.lists[orderIndex];
				let data = [];
				let index = 0;
				// 更新选择
				data[index] = this.couponData[this.couponIndex];
				console.log(data[index])

				let coupon_discount = 0;
				let coupon_freight = 0;

				console.log(data[index] != undefined)
				// order.freight.price = order.freight_price_bak;
				console.log(order.sub_price)
				order.sub_price = order.order_price;
				console.log('m', order)
				if (data[index] != undefined) {


					// @ 精度计算 this.$wanlshop.bcadd('0.132123',0.132123)
					// 满减计算
					console.log(order)
					console.log('malong')
					if (data[index].type == 'reduction' || (data[index].type == 'vip' && data[index].usertype ==
							'reduction')) {
						order.freight.price = order.freight_price_bak;
						order.sub_price = this.$wanlshop.bcsub(this.$wanlshop.bcadd(order.order_price, 0), data[index]
							.price);
						if (order.sub_price < 0) {
							order.sub_price = 0.01;
						}
						coupon_discount = data[index].price;
					}
					// 折扣计算  前端出问题
					if (data[index].type == 'discount' || (data[index].type == 'vip' && data[index].usertype ==
							'discount')) {
						let discount = data[index].discount > 10 ? this.$wanlshop.bcdiv(data[index].discount, 100) :
							this
							.$wanlshop.bcdiv(data[index].discount, 10);
						order.freight.price = order.freight_price_bak;
						order.sub_price = this.$wanlshop.bcadd(this.$wanlshop.bcmul(order.order_price, discount),
							0) // order.freight.price);
						coupon_discount = data[index].price;
					}
					// 包邮计算
					if (data[index].type == 'shipping') {
						coupon_freight = order.freight_price_bak;
						order.freight.price = 0;
						order.sub_price = order.order_price;
					}
				}
				order.freight_new = order.freight.price;
				console.log(order.sub_price)
				order.sub_price = this.$wanlshop.bcadd(order.sub_price, order.transport_new);
				console.log(order.sub_price)


				order.sub_price = this.$wanlshop.bcadd(order.sub_price, order.freight_new);
				order.coupon_freight = coupon_freight
				order.coupon_discount = coupon_discount;

				// 精度计算合计
				this.orderData.statis.allsub = 0;
				this.orderData.statis.coupon_freight = 0;
				this.orderData.statis.coupon_discount = 0;
				this.orderData.statis.coupon_goods = 0;
				this.orderData.statis.allcoupon = 0;
				this.orderData.statis.order_price = 0;
				this.orderData.statis.freight_new = 0;
				this.orderData.statis.transport_new = 0;
				console.log(this.orderData.lists[i])
				for (var i = 0; i < this.orderData.lists.length; i++) {
					this.orderData.statis.allsub = this.$wanlshop.bcadd(this.orderData.statis.allsub, this.orderData
						.lists[
							i].sub_price);
					// this.orderData.statis.coupon_freight = this.$wanlshop.bcadd(this.orderData.statis.coupon_freight,
					// 	this
					// 	.orderData.lists[i].coupon_freight);
					// this.orderData.statis.coupon_discount = this.$wanlshop.bcadd(this.orderData.statis.coupon_discount,
					// 	this.orderData.lists[i].coupon_discount);
					// this.orderData.statis.coupon_goods = this.$wanlshop.bcadd(this.orderData.statis.coupon_goods, this
					// 	.orderData.lists[i].coupon_goods);
					// this.orderData.statis.order_price = this.$wanlshop.bcadd(this.orderData.statis.order_price, this
					// 	.orderData.lists[i].order_price);
					// this.orderData.statis.freight_new = this.$wanlshop.bcadd(this.orderData.statis.freight_new, this
					// 	.orderData.lists[i].freight_new);
					// this.orderData.statis.transport_new = this.$wanlshop.bcadd(this.orderData.statis.transport_new, this
					// 	.orderData.lists[i].transport_new);
					// this.orderData.statis.allcoupon = this.$wanlshop.bcadd(this.orderData.statis.allcoupon, this
					// 	.orderData
					// 	.statis.coupon_freight);
					// this.orderData.statis.allcoupon = this.$wanlshop.bcadd(this.orderData.statis.allcoupon, this
					// 	.orderData
					// 	.statis.coupon_goods);
					// this.orderData.statis.allcoupon = this.$wanlshop.bcadd(this.orderData.statis.allcoupon, this
					// 	.orderData
					// 	.statis.coupon_discount);
				};
				this.modalName = null;
				console.log(this.orderData.statis)
			},
			// 修改数量
			changeNum(num) {
				num = num == 0 ? 1 : num;
				this.orderData.lists[0].number = num;
				this.orderData.lists[0].products[0].number = num;
				this.orderData.statis.allnum = num;
				// 计算价格
				this.orderData.lists[0].sub_price = this.$wanlshop.bcmul(this.orderData.lists[0].products[0].sku.price,
					num);

				this.orderData.statis.allsub = this.$wanlshop.bcmul(this.orderData.lists[0].products[0].sku.price, num);
			},
			addAddress(type) {

				this.$wanlshop.to(`/pages/user/address/addressManage?type=${type}`);
			},
			userAddress() {
				this.$wanlshop.to('/pages/user/address/address?source=1');
			},
			// 弹出层，暂时不需要但后续版本可能需要
			showModal(name) {
				this.modalName = name;
			},
			// 关闭弹出层
			hideModal() {
				this.modalName = null;
			},
			// 数组去重并字符串
			unique(arr) {
				return Array.from(new Set(arr)).join(',');
			},
			//禁止父元素滑动
			moveHandle() {},
			setFreight(index, key, type) { //弹出框 显示
				/* {
						name: '物流自提',
						id: 1
					},  */
				console.log(index, key, type);
				console.log(this.orderData.lists[index].products, key, type);
				let kuaidi = this.orderData.lists[index].products.every(item => item.is_kuaidi === 1)
				this.freightItems = [{
					name: '到店自取',
					id: 5
				}, {
					name: '一键到家',
					id: 2
				}];
				if (kuaidi) {
					this.freightItems.push({
						name: '快递配送',
						id: 3
					})
				}
				if (type == 'service') {
					this.freightItems = [{
						name: '无',
						id: -1
					}, {
						name: '秒送',
						id: 4
					}];
				}
				this.modalName = type
				this.freightIndex = index;
				console.log(this.onloadNum, 'this.onloadNum', );
				if (type != 'onload') {

					if (this.orderData.lists[index].products && this.orderData.lists[index]['s_freight_id']) {
						console.log('==', this.orderData.lists[this.freightIndex]['s_freight_id']);
						this.temp_id = this.orderData.lists[this.freightIndex]['s_freight_id'];
					} else {
						this.temp_id = null
					}
				}
			},

			selectFreight(id, item, index) { // 弹出框 选择数据
				console.log(id, item, this.modalName);
				console.log(this.freightIndex, 'x');
				console.log(this.orderData.lists);
				if (this.modalName == 'service') { //配送方式 秒送
					if (this.orderData.lists[this.freightIndex] && this.orderData.lists[this.freightIndex].is_send ==
						false) {
						uni.showToast({
							title: '当前收货地址不支持秒送服务',
							icon: 'none'
						})
						return
					}
					this.orderData.lists[this.freightIndex]['s_service_id'] = id;

					this.orderData.lists[this.freightIndex]['s_service_detail'] = item;
					let frieghtDataItems = this.freightItems.filter(item => item['id'] == id);
					// console.log(frieghtDataItems)
					this.frieghtDataItems = frieghtDataItems[0]['child'] ?? [];

					this.orderData.lists[this.freightIndex]['s_service_data_id'] = 0;
					this.orderData.lists[this.freightIndex]['s_service_data_detail'] = [];
					this.orderData.lists[this.freightIndex]['service_new'] = 0;
					if (this.frieghtDataItems.length > 0) {
						this.selectFreightData(this.frieghtDataItems[0]['id'], this.frieghtDataItems[0])
					}
					this.temp_id1 = id;
					this.ts = (new Date()).getTime();
				} else { //配送方式

					if (this.orderData.lists[this.freightIndex] && this.orderData.lists[this.freightIndex].open_send ==
						false && this.modalName == 'freight' && item
						.name == '一键到家') {
						uni.showToast({
							title: '当前收货地址不支持一键到家',
							icon: 'none'
						})
						return
					}
					this.temp_id1 = -1
					this.orderData.lists[this.freightIndex]['s_freight_id'] = id;
					this.orderData.lists[this.freightIndex]['s_freight_detail'] = item;
					let frieghtDataItems = this.freightItems.filter(item => item['id'] == id);
					this.frieghtDataItems = frieghtDataItems[0]['child'] ?? [];
					this.orderData.lists[this.freightIndex]['s_freight_data_id'] = 0;
					this.orderData.lists[this.freightIndex]['s_freight_data_detail'] = [];
					this.orderData.lists[this.freightIndex]['freight_new'] = 0;
					this.orderData.lists[this.freightIndex]['s_transport_id'] = undefined;
					this.orderData.lists[this.freightIndex]['transport_count'] = undefined;
					this.orderData.lists[this.freightIndex]['s_transport_detail'] = undefined;
					// this.orderData.lists[this.transportTypeIndex][this.transportTypeKey]['transport_new'] = 0;
					this.orderData.lists[this.freightIndex]['s_service_detail'] = {
						name: '无',
						id: -1
					}

					let freight = 0;
					this.orderData.lists[this.freightIndex].products.forEach(item => {
						console.log(item['freight_new']);
					});
					if (this.frieghtDataItems.length > 0) {
						this.selectFreightData(this.frieghtDataItems[0]['id'], this.frieghtDataItems[0])
					}
					this.temp_id = id;
					this.ts = (new Date()).getTime();

				}
				// 计算价格
				let data = this.orderData.lists[this.freightIndex]
				if (!data.myfreight) {
					// 物流自提
					data.mylogistics_price = JSON.parse(JSON.stringify(data.logistics_price))
					// 秒送
					data.myfreightsendfee = JSON.parse(JSON.stringify(data.freight_send_fee))
					// 到店自取
					data.mypickup_price = JSON.parse(JSON.stringify(data.pickup_price))
					// 快递
					data.myfreight = JSON.parse(JSON.stringify(data.freight))
				}
				console.log(this.freightIndex);
				let coupon = this.orderData.lists[this.freightIndex].coupon.find(a => a.choice === true)
				if (coupon) {
					console.log('优惠券', coupon);
					console.log('xx', data.freight.price);
					let couponData = {}
					let fee_price = 0
					if (item.name == '快递配送') {
						fee_price = JSON.parse(JSON.stringify(data.myfreight)).price
					}
					if (item.name == '到店自取') {
						fee_price = JSON.parse(JSON.stringify(data.mypickup_price)).price
					}
					if (item.name == '物流自提') {
						fee_price = JSON.parse(JSON.stringify(data.mylogistics_price)).price
					}
					if (item.name == '一键到家') {
						fee_price = JSON.parse(JSON.stringify(data.myfreightsendfee)).price
					}
					if (item.name == '无') {
						fee_price = JSON.parse(JSON.stringify(data.myfreightsendfee)).price
					}
					if (item.name == '秒送') {
						fee_price = this.$wanlshop.bcadd(data.freight_send_fee.price, data.flash_send_fee)
					}
					console.log(fee_price);
					if (coupon.type == 'reduction' || (coupon.type == 'vip' && coupon.usertype ==
							'reduction')) {
						console.log('满减券', data.order_price);
						if (item.name == '物流自提') {
							data.freight = JSON.parse(JSON.stringify(data.mylogistics_price))
						}
						if (item.name == '快递配送') {
							data.freight = JSON.parse(JSON.stringify(data.myfreight))
						}
						if (item.name == '到店自取') {
							data.freight = JSON.parse(JSON.stringify(data.mypickup_price))
						}
						if (item.name == '一键到家') {
							data.freight = JSON.parse(JSON.stringify(data.myfreightsendfee))
						}
						data.sub_price = this.$wanlshop.bcsub(this.$wanlshop.bcadd(data.order_price, fee_price), coupon
							.price);
						// bcsub 减法 
						console.log(data.sub_price)
						if (data.sub_price < 0) {
							data.sub_price = 0.01;
						}
					}
					// 折扣计算  前端出问题
					if (coupon.type == 'discount' || (coupon.type == 'vip' && coupon.usertype ==
							'discount')) {
						console.log('折扣券');
						if (item.name == '快递配送') {
							data.freight = JSON.parse(JSON.stringify(data.myfreight))
						}
						if (item.name == '到店自取') {
							data.freight = JSON.parse(JSON.stringify(data.mypickup_price))
						}
						if (item.name == '物流自提') {
							data.freight = JSON.parse(JSON.stringify(data.mylogistics_price))
						}
						if (item.name == '一键到家') {
							data.freight = JSON.parse(JSON.stringify(data.myfreightsendfee))
						}
						let discount = coupon.discount > 10 ? this.$wanlshop.bcdiv(coupon.discount, 100) :
							this.$wanlshop.bcdiv(coupon.discount, 10);
						data.sub_price = this.$wanlshop.bcadd(this.$wanlshop.bcmul(data.order_price, discount),
							fee_price)
					}
					// 包邮计算
					if (coupon.type == 'shipping') { //包邮
						console.log('包邮');
						if (item.name === '物流自提' || item.name === '快递配送' || item.name === '一键到家' || item.name == '到店自取') {
							data.freight.price = this.$wanlshop.bcadd(0, 0);
							data.sub_price = data.order_price
						}
						if (item.name == '秒送') {
							console.log('优惠券 ---秒送');
							data.sub_price = this.$wanlshop.bcadd(data.order_price, data.flash_send_fee)
						}
					}
				} else {
					if (item.name == '快递配送') {
						data.freight = JSON.parse(JSON.stringify(data.myfreight))
						data.sub_price = this.$wanlshop.bcadd(data.freight_price_bak, data.goods_price)
					} else if (item.name == '到店自取') {
						data.freight = JSON.parse(JSON.stringify(data.mypickup_price))
						data.sub_price = this.$wanlshop.bcadd(data.mypickup_price.price, data.goods_price)
					} else if (item.name == '物流自提') {
						data.freight = JSON.parse(JSON.stringify(data.mylogistics_price))
						data.sub_price = this.$wanlshop.bcadd(data.mypickup_price.price, data.goods_price)
					} else if (item.name == '一键到家') {
						data.freight = JSON.parse(JSON.stringify(data.myfreightsendfee))
						data.sub_price = this.$wanlshop.bcadd(data.freight_send_fee.price, data.goods_price)
					} else if (item.name == '秒送') {
						console.log('进入了秒送');
						data.sub_price = this.$wanlshop.bcadd(this.$wanlshop.bcadd(data.goods_price, data
							.freight_send_fee.price), data.flash_send_fee)
					} else if (item.name == '无') {
						data.sub_price = this.$wanlshop.bcadd(data.freight_send_fee.price, data.goods_price)
					}
				}



				this.orderData.statis.allsub = 0
				this.orderData.lists.forEach(a => {
					this.orderData.statis.allsub = this.$wanlshop.bcadd(this.orderData.statis.allsub, Number(a
						.sub_price))
				})

			},
			setFreightData(index, key) {
				console.log(index, key);
				this.modalName = "freight_data"
				this.temp_id = this.orderData.lists[index]['s_freight_data_id'];
				let freight = 0;


			},
			// 计算运费
			selectFreightData(id, item) {
				this.orderData.lists[this.freightIndex]['s_freight_data_id'] = id;
				this.orderData.lists[this.freightIndex]['s_freight_data_detail'] = item;
				this.orderData.lists[this.freightIndex]['freight_new'] = this.orderData.lists[
					this.freightIndex]['freight_all'][id];
				this.temp_id = id;
				this.ts = (new Date()).getTime();
				let freight = 0;

			},
			setTransportType(index, key) {
				console.log(index, key);
				this.transportTypeIndex = index;
				this.transportTypeKey = key;
				this.modalName = "transport"
				this.temp_transport_id = this.orderData.lists[index].products[key]['s_transport_id'];
				console.log(this.temp_transport_id)
			},
			selectTransportType(id, item) {
				console.log(id, item)
				this.orderData.lists[this.transportTypeIndex].products[this.transportTypeKey]['s_transport_id'] = id;
				this.orderData.lists[this.transportTypeIndex].products[this.transportTypeKey]['s_transport_detail'] =
					item;
				let price = "0.00";
				if (id == 0) {
					price = this.orderData.lists[this.transportTypeIndex].products[this.transportTypeKey][
						'transport_all'
					][
						0
					];
				}
				if (id == 1) {
					this.orderData.lists[this.transportTypeIndex].products[this.transportTypeKey]['transport_count'] =
						1;
					price = this.orderData.lists[this.transportTypeIndex].products[this.transportTypeKey][
						'transport_all'
					][
						1
					];

				}
				this.orderData.lists[this.transportTypeIndex].products[this.transportTypeKey]['transport_new'] = this
					.$wanlshop.bcmul(
						price + '',
						this.orderData.lists[this.transportTypeIndex].products[this.transportTypeKey]['number']

					);
				this.temp_transport_id = id;
				this.ts = (new Date()).getTime();
			},
			callPhone(number = "028-83177139") {
				console.log(number)
				uni.makePhoneCall({
					phoneNumber: number,
					success(res) {
						console.log(res, '---<>')
					},
					fail(err) {
						console.log(err)
					}
				})
			},
			set_transport_count(index, key, count) {
				if (count == -1 && this.orderData.lists[index].products[key]['transport_count'] == 1) return;
				this.orderData.lists[index].products[key]['transport_count'] += count;
				this.orderData.lists[index].products[key]['transport_new'] = this.$wanlshop.bcmul(
					this.$wanlshop.bcmul(
						this.orderData.lists[index].products[key]['transport_count'],
						this.orderData.lists[index].products[key]['transport_all'][1]
					),
					this.orderData.lists[index].products[key]['number']
				)
				this.ts = (new Date()).getTime();
			},
			show_detail() {
				console.log('detail')
				this.showDetail = !this.showDetail
			}
		}
	};
</script>

<style scoped lang="scss">
	.shopavatar {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.address {
		.cu-item {
			align-items: center !important;

			.cu-avatar1 {
				width: 100rpx !important;
				height: 100rpx !important;
			}

			.content {
				left: 160rpx !important;
				width: calc(100% - 240rpx) !important;
			}
		}
	}

	.cu-modal.bottom-modal.show.m-safe-area {
		;
		margin-bottom: calc(50px + env(safe-area-inset-bottom));
	}

	.coupon-item {
		display: flex;
		justify-content: space-between;
	}

	.m-price {
		font-size: 40rpx !important;
	}

	.freight-item {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 180rpx;
		height: 64rpx;
		background: #FFFFFF;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #4D4D4D;
		text-align: left;
		font-style: normal;
		text-transform: none;
		margin-top: 40rpx;

		&.active {
			background-color: #fe6600;
			color: white;
		}
	}
</style>